package br.com.upis.sispat.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import br.com.upis.sispat.entity.Patrimonio;

@Component
@Scope("singleton")
public class PatrimonioConverter implements Converter {
	
	public Object getAsObject(FacesContext context, UIComponent component, String valor) {  
        if(valor == null || valor.equals("Selecione") || valor.length()==0)return null;
        Patrimonio patrimonio = new Patrimonio();
        patrimonio.setCodigo(Long.valueOf(valor));
        return patrimonio;  
    }  
  
    public String getAsString(FacesContext context, UIComponent component, Object object) {  
        if(object == null)return null;  
        return ((Patrimonio)object).getCodigo().toString();  
    }
    
} 
